from Acquisition import aq_inner
import xmlrpclib

from Products.Five.browser import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile

from portalh8.services import config

class BuscaCohabView(BrowserView):
    
    __call__ = ViewPageTemplateFile('busca_cohab.pt')
    
    def buscar_aidentu(self):
        nome = self.context.REQUEST.get('nome','')
        if not nome:
            return []
        
        server = xmlrpclib.Server(config.AIDENTU_XMLRPC,allow_none=True)
        iteanos = server.get_iteanos(config.AIDENTU_PASSCODE,nome)
        return iteanos
    
    def permissao_ver(self):
        return 'Authenticated' in self.context.portal_membership.getAuthenticatedMember().getRoles()
    
    def paridade(self,num):
        if num%2:
            return 'even'
        else:
            return 'odd'